//
//  GYGradientView.m
//  INMOTION
//
//  Created by apple03 on 2018/4/4.
//  Copyright © 2018年 Inmotion. All rights reserved.
//

#import "GYGradientView.h"

@interface GYGradientView()
@property (nonatomic, strong) CAGradientLayer *gradientLayer;

@end

@implementation GYGradientView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if(self) {
        self.clipsToBounds = YES;
        [self configGradientBackgroundColor];
        self.layer.cornerRadius = self.bounds.size.height /2;
    }
    return self;
}

-(void)awakeFromNib {
    [super awakeFromNib];
    self.clipsToBounds = YES;
    [self configGradientBackgroundColor];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    [self configGradientBackgroundColor];
    if (self.bounds.size.height > 100) {
        self.layer.cornerRadius = 10;
    } else {
        self.layer.cornerRadius = self.bounds.size.height /2;
    }
}

- (void)configGradientBackgroundColor {
    self.gradientLayer = [CAGradientLayer layer];
    self.gradientLayer.frame = self.bounds;
    [self.layer addSublayer:self.gradientLayer];
    self.gradientLayer.startPoint = CGPointMake(0, 0);
    self.gradientLayer.endPoint = CGPointMake(1, 0);
    
    self.gradientLayer.colors = @[(__bridge id)[UIColor colorWithRed:249/255.0 green:89/255.0 blue:32/255.0 alpha:1].CGColor,
                                  (__bridge id)[UIColor colorWithRed:247/255.0 green:64/255.0 blue:64/255.0 alpha:1].CGColor];
    
    self.gradientLayer.locations = @[@(0.5f),@(1.0f)];
}

@end
